package com.itheima.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.common.TokenHolder;
import com.itheima.domain.OrderDetail;
import com.itheima.domain.Orders;
import com.itheima.dto.DishDto;
import com.itheima.service.OrderDetailService;
import com.itheima.service.OrdersService;
import com.itheima.vo.OrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    @Autowired
    private OrderDetailService orderDetailService;

    /**
     * 用户下单
     *
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders) {
        log.info("订单数据：{}", orders);
        boolean result = ordersService.submit(orders);
        if (!result) {
            return R.error("下单失败");
        }
        return R.success("下单成功");
    }

//    /**
//     * 前台订单列表的分页查询
//     * @param page
//     * @param pageSize
//     * @return
//     */
//    @GetMapping("/userPage")
//    public R<Page<OrderVo>> userPage(Integer page ,Integer pageSize ){
//        List<OrderVo> orderVoList = ordersService.userPage(page, pageSize);
//
//        Page<OrderVo> orderVoPage = new Page<>();
//
//        orderVoPage.setSize(pageSize);
//        orderVoPage.setCurrent(page);
//        orderVoPage.setRecords(orderVoList);
//
//        return R.success(orderVoPage);
//    }

    @GetMapping("/userPage")
    public R userPage(int page, int pageSize) {
        Page pageInfo = ordersService.userPage(page, pageSize);
        return R.success(pageInfo);
    }
}

